package com.cool.collect.springcode.a06;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


/**
 * @author xiemiao
 * @description
 * @date 2023/08/30
 */
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {

    private static final Logger log = LoggerFactory.getLogger(MyBean.class);

    @Override
    public void setBeanName(String name) {
        log.info("当前bean:{}，名字:{}", this, name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("当前bean:{}，容器是:{}", this, applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("当前bean:{}初始化", this);
    }

    @Autowired
    public void aaa(ApplicationContext applicationContext) {
        log.info("当前bean:{},使用@Autowired 容器是{}", this, applicationContext);
    }

    @PostConstruct
    public void init() {
        log.info("当前bean:{},使用@PostConstruct初始化", this);
    }
}
